package com.huawei.hms.activity;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import com.huawei.hms.activity.a.a;
import com.huawei.hms.activity.a.c;
import com.huawei.hms.activity.a.d;
import com.huawei.hms.common.internal.RequestHeader;
import com.huawei.hms.common.internal.TransactionIdCreater;
import com.huawei.hms.support.api.entity.core.CoreNaming;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.utils.Util;

public class ForegroundIntentBuilder {
    private Activity a;
    private RequestHeader b;
    private String c;
    private d d;

    public ForegroundIntentBuilder(Activity activity) throws IllegalArgumentException {
        if (activity == null) {
            throw new IllegalArgumentException("listener must not be null.");
        }
        this.a = activity;
        this.b = new RequestHeader();
        this.b.setPkgName(activity.getPackageName());
        this.b.setSdkVersion(30003300);
        this.c = "";
        this.d = new d();
        this.d.a(30000000);
    }

    public Intent build() {
        Intent intentStartBridgeActivity = BridgeActivity.getIntentStartBridgeActivity(this.a, a.class.getName());
        if (this.b.getAppID() == null) {
            this.b.setAppID(Util.getAppId(this.a) + HiAnalyticsConstant.REPORT_VAL_SEPARATOR);
        } else {
            this.b.setAppID(Util.getAppId(this.a) + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.b.getAppID());
        }
        if (TextUtils.isEmpty(this.b.getTransactionId())) {
            this.b.setTransactionId(TransactionIdCreater.getId(this.b.getAppID(), CoreNaming.HUBREQUEST));
        }
        intentStartBridgeActivity.putExtra("HMS_FOREGROUND_REQ_HEADER", this.b.toJson());
        intentStartBridgeActivity.putExtra("HMS_FOREGROUND_REQ_BODY", this.c);
        intentStartBridgeActivity.putExtra("HMS_FOREGROUND_REQ_INNER", this.d);
        return intentStartBridgeActivity;
    }

    public ForegroundIntentBuilder setSubAppId(String str) {
        this.b.setAppID(str);
        return this;
    }

    public ForegroundIntentBuilder setRequestBody(String str) {
        this.c = str;
        return this;
    }

    public ForegroundIntentBuilder setMinApkVersion(int i) {
        this.d.a(i);
        return this;
    }

    public ForegroundIntentBuilder setResponseCallback(String str, a aVar) {
        this.d.a(str);
        c.a().a(str, aVar);
        return this;
    }

    public ForegroundIntentBuilder setResponseCallback(String str) {
        this.d.a(str);
        return this;
    }

    public ForegroundIntentBuilder setAction(String str) {
        this.b.setApiName(str);
        return this;
    }

    public ForegroundIntentBuilder setServiceName(String str) {
        this.b.setSrvName(str);
        return this;
    }

    public ForegroundIntentBuilder setTransactionId(String str) {
        this.b.setTransactionId(str);
        return this;
    }

    public ForegroundIntentBuilder setKitSdkVersion(int i) {
        this.b.setKitSdkVersion(i);
        return this;
    }

    public static void registerResponseCallback(String str, a aVar) {
        c.a().a(str, aVar);
    }

    public static void unregisterResponseCallback(String str) {
        c.a().a(str);
    }
}
